﻿using ETask.Api.Dtos;
using ETask.Api.Services;
using Microsoft.AspNetCore.Mvc;

namespace ETask.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TaskFileController : ControllerBase
    {

        private readonly ITaskFileService _taskFileService;

        public TaskFileController(ITaskFileService taskFileService)
        {
            _taskFileService = taskFileService;
        }

        [HttpPost("upload")]
        public async Task<IActionResult> Upload(IFormFile formFile, [FromForm] string folderId)
        {
            var res = await _taskFileService.Upload(formFile, folderId);
            return Ok(res);
        }

        [HttpPost("delById")]
        public async Task<IActionResult> DelById([FromBody]PrimaryKey key)
        {
            var res = await _taskFileService.DelByFileId(key.Id);
            return Ok(res);
        }


        [HttpPost("getByFolderId")]
        public async Task<IActionResult> GetByFolderId([FromBody]PrimaryKey key)
        {
            var res = await _taskFileService.GetListByFolderIdAsync(key.Key);
            return Ok(res);
        }

        [HttpPost("delByFolderId")]
        public async Task<IActionResult> DelByFolderId([FromBody]PrimaryKey key )
        {
            var res = await _taskFileService.DeleteByFolderId(key.Key);
            return Ok(res);
        }
    }
}
